package ModelLayer;

import java.util.*;

public class DeliveryContainer{
    private ArrayList<Delivery> deliveryContainer;
    private static DeliveryContainer instance;

    private DeliveryContainer(){
        deliveryContainer = new ArrayList<Delivery>();
    }

    public static DeliveryContainer getInstance(){
        if(instance == null)
            instance = new DeliveryContainer();
        return instance;
    }

    public void addDelivery(Delivery delivery){
        deliveryContainer.add(delivery);
    }

    public Delivery findDeliveryById(int id){
        Delivery dObject = null;
        int index = 0;
        boolean found = false;
        while(index < deliveryContainer.size() && !found)
        {
            dObject = deliveryContainer.get(index); 
            if(dObject.getDeliveryID()== id)
            {
                found = true;
            }
            else{
                index++;
            }
        }
        if(found){
            return deliveryContainer.get(index) ;
        }else{
            return  null;
        }
    }
    
    public ArrayList<Delivery> getDeliveryList()
    {
        return deliveryContainer;
    }

    public void deleteDelivery(Delivery d){
        if(deliveryContainer.contains(d))
            deliveryContainer.remove(d);
    }
}